<!--************************************************************ -->
<!--* 文件创建日期：2010                                  * -->
<!--* 文件修改日期：			                                   * -->
<!--************************************************************ -->
<!--JSP初始化设置-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.infomanage.po.*" %>
<%@page import="java.util.*" %>
<%@page import="com.infomanage.vo.*" %>
<%@page import="com.infomanage.enums.*"%>
<%@page import="com.infomanage.service.syscfg.*"%>
<%  response.addDateHeader("Expires", 0);response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-cache");%>
<%
	request.setCharacterEncoding("UTF-8");
	String userId = request.getParameter("userId");
    if(userId == null) userId = "";
    
    User user = UserService.loadUser(request, response, out);
    String username = "";
    int deptLevel = -1;
    int roleId = -1;
    String description = "";
    String password = "";
    int associatedDept = -1;
    String personName = "";
    int personId = -1;
    if(user != null) {
    	deptLevel = user.getDeptLevel();
	    username = user.getUserName();
	    roleId = user.getRoleId();
	    password = user.getPassword();
	    description = user.getDescription() == null ? "" : user.getDescription();
	    associatedDept = user.getAssociatedDept();
	    personName = user.getPersonName() == null ? "" : user.getPersonName();
	    personId = user.getPersonId() == null ? -1 : user.getPersonId();
    } 
%>
<html>
<head>
	<title>用户管理</title>
	<META HTTP-EQUIV="Pragma" CONTENT="no-cache">	
	<link href="../../css/table.css" rel="stylesheet" type="text/css">
	<link href="../../css/calendar.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="../../js/calendar.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript">
	   function init() {
		   if("" != "<%=userId%>") { // 修改
			   form1.password1.value = "<%=password%>";
			   form1.password.value = "<%=password%>";
			   form1.roleId.value = "<%=roleId%>";
			   form1.description.value = "<%=description%>";
			   var role = document.getElementById("roleId");
	   		   if(role.value == "<%=RoleType.ZDADMIN.value()%>" || role.value == "<%=RoleType.GENERALUSER.value()%>"){
	   		      form1.associatedDept.value = "<%=associatedDept%>";
	   			  document.getElementById("roleRow").style.display = "";
	   		    }
		   }
	   }
	   
	   function selectNode(id, title){
			currTreeInputObj.value = title;
			currTreeInputObj.nextSibling.value = id;
			var treeFrame = document.getElementById("treeFrame");
			treeFrame.style.display = "none";
       }
       
	   // 提交
	   function doSubmit(){
	   		if(validate()){
	   			return;
	   		}
		 	if("" == "<%=userId%>") {
		 		form1.actionType.value = "add";
			}else {
		 		form1.actionType.value = "modify";
			}
		 	form1.submit();
	   }

	   function showError(error){
		   alert(error);
	   }

	   function showInfo(info){
		   alert(info);
		   window.returnValue = "ok";
		   window.close();
	   }
	   
	   function changeRole(){
	   		var role = document.getElementById("roleId");
	   		if(role.value == "<%=RoleType.ZDADMIN.value()%>" || role.value == "<%=RoleType.GENERALUSER.value()%>"){
	   			document.getElementById("roleRow").style.display = "";
	   		}else{
	   			document.getElementById("roleRow").style.display = "none";
	   		}
	   }
	   
	   function validate(){
	   		if(form1.username.value == ""){
	   			alert("用户名不能为空！");
	   			return true;
	   		}
	   		
	   		if(form1.password1.value == ""){
	   			alert("密码不能为空！");
	   			return true;
	   		}
	   		
	   		if(form1.password1.value != form1.password.value){
	   			alert("两次输入密码不一致！");
	   			return true;
	   		}
	   		
	   		return false;
	   }
	</script>
</head>
<body  rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0" onclick="clickBody();" onload="init();">
	<form name="form1" action="userManage_action.jsp" method="post" target="actionFrame">
	<input type="hidden" name="userId" value="<%=userId%>">
	<input type="hidden" name="actionType">
	<table class="dialogTable" cellpadding="0" cellspacing="0">
		<!-- 表头-->
		<tr class="dialogTableHeader">
			<td>用户管理</td>
		</tr>
		<!-- 表数据-->
		<tr class="dialogTableContent">
			<td>
				<!-- 数据项 -->
				<table class="dataTable">
					<col width="30%">
					<col width="70%">
					<tr>
						<td class="field">
							用户名
						</td>
						<td>
						<%
						if(com.infomanage.util.Consts.SUPER_ADMIN_NAME.equals(username)){
						%>
							<input style="width: 100%;" name="username" value="<%=username %>" readonly/>
						<%
						}else{
						%>						
							<input style="width: 100%;" name="username" value="<%=username %>"/>
						<%
						}
						%>
						</td>
					</tr>
					
					<tr>
						<td class="field">
							密码
						</td>
						<td>
							<input style="width: 100%;" name="password1" type="password"/>
						</td>
					</tr>
					<tr>
						<td class="field">
							确认密码
						</td>
						<td>
							<input style="width: 100%;" name="password" type="password"/>
						</td>
					</tr>
					<tr>
						<td class="field">
							角色
						</td>
						<td>
								<%
								if(com.infomanage.util.Consts.SUPER_ADMIN_NAME.equals(username)){
								%>
										<input style="width: 100%" type="hidden" name="roleId" value="<%= RoleType.SYSADMIN.value()%>">
											<select style="width: 100%"  disabled>
									   <%
					                   		for(RoleType type: RoleType.getMembers()){
					                   %>			
					                   		<option value="<%= type.value() %>"><%= type.title()%></option>
					                   <%
					                   		}
					                   %>
											</select>
								<%
								}else{
								%>						
									<select style="width: 100%" name="roleId" onchange="changeRole();">
							   <%
			                   		for(RoleType type: RoleType.getMembers()){
			                   %>			
			                   		<option value="<%= type.value() %>"><%= type.title()%></option>
			                   <%
			                   		}
			                   %>
									</select>
								<%
								}
								%>

						</td>
					</tr>
					<tr style="display:none" id="roleRow">
						<td class="field">
							关联单位
						</td>
						<td>
							<select style="width: 100%;" name="associatedDept">
								<%
									  List<Department> associatedDepts = UserService.listAssociatedDepts();
			                    	  for(Department dept: associatedDepts){
			                    %>			
			                   		<option value="<%= dept.getDeptId() %>"><%= dept.getName()%></option>
			                    <%
			                   		}
			                    %>
							</select>
						</td>
					</tr>
					<tr>
						<td class="field">
							关联员工
						</td>
						<td>
							<span class="treeSpan" onclick="showTree(this, '../common/personTree.jsp');" treeSelect="true">
								<input name="personName" value="<%=personName %>" style="width: 338px" readonly="readonly" treeSelect="true"><input name="personId" value="<%=personId%>" type="hidden">
							</span>
						</td>
					</tr>
					<tr style="height: 100px">
						<td class="field">
							备注
						</td>
						<td valign="top">
							<textarea style="width: 100%;height: 100%" name="description"></textarea>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="tableBtn">
				<span onclick="doSubmit();">确定</span>
				<span onclick="window.close();">取消</span>
			</td>
		</tr>
		<tr valign="top">
			<td colspan="2">
				&nbsp;
			</td>
		</tr>
	</table>
	</form>
	<iframe src="#" frameborder="0" id="treeFrame" name="frame" style="display: none;position: absolute;"></iframe>
	<iframe src="#" name="actionFrame" style="display: none;"></iframe>
</body>
</html>